package com.fh.modules.ums.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fh.common.api.vo.Result;
import com.fh.common.aspect.annotation.AutoLog;
import com.fh.common.constant.CommonConstant;
import com.fh.common.query.QueryWrapperUtil;
import com.fh.modules.ums.entity.UmsPartnerApply;
import com.fh.modules.ums.service.IUmsPartnerApplyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

 /**
 * @Title: Controller
 * @Description: 合伙人申请
 * @author： code generator
 * @date：   2019-09-25
 * @version： V1.0
 */
@RestController
@Slf4j
@Api("合伙人申请")
public class UmsPartnerApplyController {
	@Autowired
	private IUmsPartnerApplyService umsPartnerApplyService;
	
	/**
	  * 分页列表查询
	 * @param umsPartnerApply
	 * @param pageNo
	 * @param pageSize
	 * @return
	 */
	@GetMapping(value = "/ums/umsPartnerApply/list")
	@ApiOperation("分页列表查询")
	@AutoLog(value="合伙人申请分页查询",logType=CommonConstant.LOG_TYPE_QUERY)
	public Result queryPageList(UmsPartnerApply umsPartnerApply,
									  @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
									  @RequestParam(name="pageSize", defaultValue="10") Integer pageSize) {
		QueryWrapper<UmsPartnerApply> queryWrapper = new QueryWrapper<UmsPartnerApply>();
		QueryWrapperUtil.initQueryWrapper(queryWrapper, umsPartnerApply);
		Page<UmsPartnerApply> page = new Page<UmsPartnerApply>(pageNo, pageSize);
		IPage<UmsPartnerApply> pageList = umsPartnerApplyService.page(page, queryWrapper);
		return Result.ok(pageList);
	}
	

	@PostMapping(value = "/ums/umsPartnerApply/apply")
	@ApiOperation("申请成为合伙人")
	@AutoLog("申请成为合伙人")
	public Result apply(@RequestBody UmsPartnerApply umsPartnerApply) {
		umsPartnerApply.setAuditStatus(0);
		umsPartnerApplyService.save(umsPartnerApply);
		return Result.ok("添加成功");
	}
	

	@PutMapping(value = "/ums/umsPartnerApply/audit")
	@ApiOperation("审核合伙人申请")
	@AutoLog("审核合伙人申请")
	public Result audit(Integer partnerApplyId,Integer auditResult,String auditMsg) {
		umsPartnerApplyService.audit(partnerApplyId,auditResult,auditMsg);
		return Result.ok("修改成功");
	}
	
	/**
	  *   通过id删除
	 * @param id
	 * @return
	 */
	@DeleteMapping(value = "/ums/umsPartnerApply/delete")
	@ApiOperation("通过id删除")
	@AutoLog("删除合伙人申请")
	public Result delete(@RequestParam(name="id",required=true) String id) {
		umsPartnerApplyService.deleteEntityByDelFlag(id);
		return Result.ok("删除成功");
	}
	
	/**
	  *  批量删除
	 * @param ids
	 * @return
	 */
	@DeleteMapping(value = "/ums/umsPartnerApply/deleteBatch")
	@ApiOperation("批量删除")
	@AutoLog("批量删除合伙人申请")
	public Result deleteBatch(@RequestParam(name="ids",required=true) String ids) {
		umsPartnerApplyService.deleteBatchEntityByDelFlag(ids);
		return Result.ok("批量删除成功");
	}
	
}
